#pragma once

#include <QObject>
#include <QMainWindow>
#include <QToolBar>
#include <QSettings>
#include <QUrl>
#include <mediaitem.h>

class ImportModule;

class PioCore : public QObject
{
    Q_OBJECT
public:

    // raw/processed type enum
    enum RawType {
        RawAndOther,
        Other,
        Raw,
        UnprocessedRaw,
        UnprocessedRawAndOther
    };

    // get the main window of the application
    virtual QMainWindow * mainwindow() = 0;

    // get the main toolbar if the main window
    virtual QToolBar * toolbar() = 0;

    // get all items in the library
    virtual QList<MediaItemPtr> all() = 0;

    // get visible items (items that are in the current view)
    virtual QList<MediaItemPtr> view() = 0;

    // get the current selection
    virtual QList<MediaItemPtr> selection() = 0;

    // get all checked items
    virtual QList<MediaItemPtr> checked() = 0;

    // returns the set of files that belong together (e. g. different file formats)
    virtual QSet<MediaItemPtr> set(MediaItemPtr item) = 0;

    // install import module
    virtual bool registerImportModule(ImportModule * im) = 0;

    // returns the root path of the primary image library
    virtual QString libraryPath() = 0;

    // returns the application settings object
    virtual QSettings & settings() = 0;

    // returns the items icon, if available
    virtual QPixmap icon(const MediaItemPtr & item, const QSize & size, bool sync) = 0;

    // loads the provided image file
    virtual QImage load(const QString & filename, const QSize & size) = 0;

    // move/rename item to new location
    virtual bool rename(MediaItemPtr item, const QString & filename) = 0;

    // remove item and delete file
    virtual bool trash(MediaItemPtr item) = 0;

public slots:
    // add file to library
    virtual void add(const QString & filename) = 0;

    // update meta data of the item
    //virtual void update(MediaItemPtr item) = 0;

    // set status bar text
    virtual void setStatus(const QString & status) = 0;

    // import files from the specified source
    virtual void import(QUrl url) = 0;

    // select or deselect item
    virtual void select(MediaItemPtr item, bool select) = 0;

    // check or uncheck item
    virtual void check(MediaItemPtr item, bool check) = 0;

    // set selection
    virtual void select(QSet<MediaItemPtr> selection) = 0;

    // clear selection
    virtual void clearSelection() = 0;

    // add overlay to the image zoom widget
    virtual void addOverlay(QWidget * overlay) = 0;

    // remove overlay from the image zoom widget
    virtual void removeOverlay(QWidget * overlay) = 0;

    // add tool widget to the sidebar
    virtual void addToolWidget(QWidget * widget, QString title) = 0;

    // remove tool widget from the sidebar
    virtual void removeToolWidget(QWidget * widget) = 0;

    // select widget from sidebar (make it visible)
    virtual void selectToolWidget(QWidget * widget) = 0;

signals:
    // is emitted when an item is shown that was previously not shown (either newly added to library or not filtered by the filters anymore)
    void shown(MediaItemPtr item);

    // is emitted when an item is hidden that was previously visible (either removed from the library or filtered out by the filters)
    void hidden(MediaItemPtr item);

    // is emitted when an item has been changed (meta data update, moved, etc.)
    void updated(MediaItemPtr item);

    // is emitted when items have been selected or deselected
    void selectionChanged(QList<MediaItemPtr> selection);

    // is emitted when the items preview icon was loaded
    void iconLoaded(MediaItemPtr item);
};
